﻿package com.codingbros.fireworks.particles 
{
	import flash.display.Shape;
	
	import flash.geom.Point;
	
	/**
	 * ...
	 * @author ...
	 */
	public class OrbitLineParticle extends Shape implements ILineParticle  
	{
		private static const MAXSPEED:Number=5;
		private static const MINSPEED:Number=2;
		
		private var currentPos:Point;
		private var lastPos:Point;
		
		private var velocity:Point;
		private var acceleration:Point;
		private var gravity:Point;	
		
		private var sideWind:Point;
		
		private var color:uint;
		
		public function OrbitLineParticle() 
		{			
			currentPos=new Point(-5 + Math.random()*10, -5 + Math.random()*10);
			lastPos=new Point();
			
			var radians:Number=Math.random()*Math.PI*2;
			var speed:Number = MINSPEED + Math.random() * (MAXSPEED - MINSPEED);
			
			velocity = new Point();
			velocity.x = Math.cos(radians)*speed;
			velocity.y = Math.sin(radians)*speed;
			
			acceleration = new Point();
			gravity = new Point();
			
			sideWind = new Point(-0.05 + Math.random()*0.1, -0.05 + Math.random()*0.1);	
			
		}
		
		public function init(color:uint):void 
		{
			this.color = color;
		}
		
		public function update():void  
		{
			lastPos = currentPos.clone();
			
			gravity = currentPos.clone();
			gravity.normalize(-0.1);
			
			acceleration = gravity;
			
			velocity = velocity.add(acceleration);	
			//velocity = velocity.add(sideWind);
			
			currentPos = currentPos.add(velocity);
		}
		
		public function draw():void  
		{
			graphics.clear();
			graphics.lineStyle(1,color,1);
			graphics.moveTo(lastPos.x, lastPos.y);
			graphics.lineTo(currentPos.x, currentPos.y);
		}
	}
}